@echo off
chcp 65001
:: 打印%~dp0
echo 当前工作目录: %~dp0

::删除原有的编译文件  %~dp0是相对路径
del /s /q  %~dp0\bin\go-utils_windwos_x86*
del /s /q  %~dp0\bin\go-utils_linux_x86*
del /s /q  %~dp0\bin\go-utils_mac_x86*

:: build for windows
set GOARCH=amd64
set GOOS=windows
go build -o %~dp0\bin\go-utils_windwos_x86.exe main.go

::build for linux
set GOARCH=amd64
set GOOS=linux
go build -o %~dp0\bin\go-utils_linux_x86 main.go

::build for mac
set GOARCH=amd64
set GOOS=darwin
go build -o %~dp0\bin\go-utils_mac_x86 main.go

set upxpd="%1"
::如果开启压缩,那么编译器每次在启动的时候会慢一些,因为需要解压缩内容到内存
IF %upxpd% equ "upx" (
    upx --best -k -o %~dp0\bin\go-utils_windwos_x86_compress.exe  %~dp0\bin\go-utils_windwos_x86.exe
    upx --best -k -o %~dp0\bin\go-utils_linux_x86_compress    %~dp0\bin\go-utils_linux_x86
    upx --best -k -o %~dp0\bin\go-utils_mac_x86_compress       %~dp0\bin\go-utils_mac_x86
) else (
	echo "no upx"
)

